package com.jzo2o.market.controller.web;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.market.model.dto.request.CouponQueryForPageReqDTO;
import com.jzo2o.market.model.dto.request.CouponSaveReqDTO;
import com.jzo2o.market.model.dto.response.CouponInfoResDTO;
import com.jzo2o.market.service.ICouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("webCouponController")
@RequestMapping("/web/coupon")
@Api(tags = "外部系统对接 - 优惠券配置相关接口")
public class CouponController {

    @Resource
    private ICouponService couponService;

    @GetMapping("/page")
    @ApiOperation("运营端分页查询优惠券配置")
    public PageResult<CouponInfoResDTO> queryForPage(CouponQueryForPageReqDTO couponQueryForPageReqDTO) {
        return couponService.queryForPage(couponQueryForPageReqDTO);
    }

    @GetMapping("/{id}")
    @ApiOperation("查询优惠券配置详情")
    @ApiImplicitParam(name = "id", value = "优惠券配置id", required = true, dataTypeClass = Long.class)
    public CouponInfoResDTO getDetail(@PathVariable("id") Long id) {
        return couponService.queryById(id);
    }

    @PostMapping("/save")
    @ApiOperation("优惠券配置保存")
    public void save(@Validated @RequestBody CouponSaveReqDTO couponSaveReqDTO) {
        couponService.save(couponSaveReqDTO);
    }

    @PostMapping("/revoke/{id}")
    @ApiOperation("优惠券撤销")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "优惠券配置id", required = true, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "updateBy", value = "更新人id", required = true, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "updator", value = "更新人姓名", required = true, dataTypeClass = String.class)
    })
    public void revoke(@PathVariable("id") Long id,
                       @RequestParam("updateBy") Long updateBy,
                       @RequestParam("updator") String updator) {
        couponService.revoke(id, updateBy, updator);
    }
}
